package com.yuanqi.dz.dc.service.impl;

import pnbclient.helper.StringHelper;
import pnbclient.util.HSClient;
import pnbclient.util.PnbLogFactory;
import pnblog.PnbLogging;
import com.powermop.service.remote.IRefundInforMation;
import com.yuanqi.service.DzDataService;
import com.yuanqitech.powermop.dz.DZDataInterface;
import com.yuanqitech.powermop.dz.DZInfo;
import com.yuanqitech.powermop.dz.DZInfoArray;

public class HaiciServiceImpl implements DZDataInterface{
public static final PnbLogging LOG = PnbLogFactory.getLogger("DZ_EXT_LOG");
    
	public static void main(String[] args) {
		DZInfoArray dz = new HaiciServiceImpl().getDZData("", "20180111");
	 
			
			
			DZInfo[] dzins= dz.getDzInfo();
			for (int i = 0; i < dzins.length; i++) {
				System.out.println(dzins[i]);
			}
			System.out.println(dzins.length);
	}
	
	public DZInfoArray getDZData(String mercharnum, String dzdate) {
		DZInfoArray dzInfoArray = new DZInfoArray();
	    String haici_dz_address ="http://127.0.0.1:15779/HCService/dzData";
	    		//DZConfigRead.getProperties("haici_dz_address");
	    if (StringHelper.isEmpty(haici_dz_address)) {
	      dzInfoArray.setRc("-1");
	      dzInfoArray.setErrormsg("获取海鹚对账数据HS地址未配置");
	      return dzInfoArray;
	    }
	    LOG.addDebug("create " + IRefundInforMation.class.getSimpleName() + " from:" + haici_dz_address);
	    try{
	      LOG.addInfo("调用HS接口入参{mercharnum:" + mercharnum + ",dzdate:" + dzdate + "}");
	      DzDataService iRefundInforMation = (DzDataService)HSClient.create(DzDataService.class, haici_dz_address);
	      dzInfoArray = iRefundInforMation.getDzData(mercharnum, dzdate);
	      if (dzInfoArray == null) {
	        dzInfoArray = new DZInfoArray();
	        dzInfoArray.setRc("-1");
	        dzInfoArray.setErrormsg("HS获取海鹚对账数据为null");
	        return dzInfoArray;
	      }
	      String rc = dzInfoArray.getRc();
	      if ((rc != null) && ("1".equals(rc))) {
	        DZInfo[] list = dzInfoArray.getDzInfo();
	        if ((list == null) || (list.length == 0)) {
	          dzInfoArray = new DZInfoArray();
	          dzInfoArray.setRc("-1");
	          dzInfoArray.setErrormsg("HS获取海鹚对账数据为空");
	          return dzInfoArray;
	        }
	        dzInfoArray = new DZInfoArray();
	        dzInfoArray.setRc("1");
	        dzInfoArray.setErrormsg("获取海鹚对账数据成功!");
	        dzInfoArray.setDzInfo(list);
	      }
	    } catch (Exception e) {
	      LOG.addError(e);
	      dzInfoArray = new DZInfoArray();
	      dzInfoArray.setRc("-1");
	      dzInfoArray.setErrormsg("HS获取海鹚对账数据异常!");
	      return dzInfoArray;
	    }

	    return dzInfoArray;
	}
}
